<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电商平台 - 首页</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: #f5f5f5;
        }
        
        .header {
            background: white;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            padding: 15px 0;
        }
        
        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .logo {
            font-size: 24px;
            font-weight: bold;
            color: #333;
        }
        
        .nav {
            display: flex;
            gap: 20px;
            align-items: center;
        }
        
        .nav a {
            text-decoration: none;
            color: #333;
            padding: 8px 16px;
            border-radius: 4px;
            transition: background-color 0.3s;
        }
        
        .nav a:hover {
            background: #f0f0f0;
        }
        
        .user-info {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .welcome {
            color: #666;
        }
        
        .logout-btn {
            background: #e74c3c;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
        }
        
        .main-content {
            max-width: 1200px;
            margin: 40px auto;
            padding: 0 20px;
        }
        
        .welcome-section {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 60px 40px;
            border-radius: 12px;
            text-align: center;
            margin-bottom: 40px;
        }
        
        .welcome-section h1 {
            font-size: 36px;
            margin-bottom: 20px;
        }
        
        .welcome-section p {
            font-size: 18px;
            opacity: 0.9;
        }
        
        .features-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 30px;
            margin-bottom: 40px;
        }
        
        .feature-card {
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            text-align: center;
        }
        
        .feature-card h3 {
            color: #333;
            margin-bottom: 15px;
            font-size: 20px;
        }
        
        .feature-card p {
            color: #666;
            line-height: 1.6;
        }
        
        .action-buttons {
            display: flex;
            gap: 15px;
            justify-content: center;
            margin-top: 20px;
        }
        
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-weight: 500;
            transition: transform 0.2s;
        }
        
        .btn:hover {
            transform: translateY(-2px);
        }
        
        .btn-primary {
            background: #667eea;
            color: white;
        }
        
        .btn-secondary {
            background: #95a5a6;
            color: white;
        }
        
        .btn-success {
            background: #27ae60;
            color: white;
        }
        
        .footer {
            background: #333;
            color: white;
            text-align: center;
            padding: 20px;
            margin-top: 60px;
        }
        
        @media (max-width: 768px) {
            .header-content {
                flex-direction: column;
                gap: 15px;
            }
            
            .nav {
                flex-wrap: wrap;
                justify-content: center;
            }
            
            .welcome-section {
                padding: 40px 20px;
            }
            
            .welcome-section h1 {
                font-size: 28px;
            }
            
            .features-grid {
                grid-template-columns: 1fr;
            }
            
            .action-buttons {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-content">
            <div class="logo">电商平台</div>
            <div class="nav">
                <a href="index.html">首页</a>
                <a href="profile.html">个人资料</a>
                <a href="change-password.html">修改密码</a>
                <div class="user-info">
                    <span class="welcome" id="welcomeText">欢迎，用户</span>
                    <button class="logout-btn" onclick="logout()">退出</button>
                </div>
            </div>
        </div>
    </div>
    
    <div class="main-content">
        <div class="welcome-section">
            <h1>欢迎来到电商平台</h1>
            <p>这里是您的购物天堂，享受便捷的购物体验</p>
        </div>
        
        <div class="features-grid">
            <div class="feature-card">
                <h3>用户管理</h3>
                <p>完善您的个人信息，管理账户安全，享受个性化服务。</p>
                <div class="action-buttons">
                    <a href="profile.html" class="btn btn-primary">个人资料</a>
                    <a href="change-password.html" class="btn btn-secondary">修改密码</a>
                </div>
            </div>
            
            <div class="feature-card">
                <h3>商品浏览</h3>
                <p>浏览丰富的商品目录，发现心仪的商品，享受购物的乐趣。</p>
                <div class="action-buttons">
                    <a href="#" class="btn btn-primary">浏览商品</a>
                    <a href="#" class="btn btn-secondary">热门推荐</a>
                </div>
            </div>
            
            <div class="feature-card">
                <h3>订单管理</h3>
                <p>查看订单状态，跟踪物流信息，管理您的购物记录。</p>
                <div class="action-buttons">
                    <a href="#" class="btn btn-primary">我的订单</a>
                    <a href="#" class="btn btn-secondary">订单历史</a>
                </div>
            </div>
        </div>
        
        <div class="features-grid">
            <div class="feature-card">
                <h3>客户服务</h3>
                <p>专业的客服团队为您提供贴心的服务支持。</p>
                <div class="action-buttons">
                    <a href="#" class="btn btn-primary">联系客服</a>
                    <a href="#" class="btn btn-secondary">帮助中心</a>
                </div>
            </div>
            
            <div class="feature-card">
                <h3>优惠活动</h3>
                <p>参与各种优惠活动，享受折扣和特价商品。</p>
                <div class="action-buttons">
                    <a href="#" class="btn btn-primary">查看活动</a>
                    <a href="#" class="btn btn-success">限时特价</a>
                </div>
            </div>
            
            <div class="feature-card">
                <h3>社区互动</h3>
                <p>与其他用户分享购物心得，参与社区讨论。</p>
                <div class="action-buttons">
                    <a href="#" class="btn btn-primary">用户论坛</a>
                    <a href="#" class="btn btn-secondary">评价分享</a>
                </div>
            </div>
        </div>
    </div>
    
    <div class="footer">
        <p>&copy; 2024 电商平台. 保留所有权利.</p>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 检查登录状态
            const token = localStorage.getItem('token');
            if (!token) {
                window.location.href = 'login.html';
                return;
            }
            
            // 获取用户信息
            loadUserInfo();
        });
        
        async function loadUserInfo() {
            try {
                const response = await fetch('/api/user/profile', {
                    headers: {
                        'Authorization': `Bearer ${localStorage.getItem('token')}`
                    }
                });
                
                if (response.status === 401) {
                    // 登录已过期
                    localStorage.removeItem('token');
                    window.location.href = 'login.html';
                    return;
                }
                
                const result = await response.json();
                
                if (result.code === 200) {
                    const user = result.data;
                    document.getElementById('welcomeText').textContent = `欢迎，${user.name || user.username}`;
                    
                    // 如果是管理员，显示管理入口
                    if (user.role === 'ADMIN') {
                        const nav = document.querySelector('.nav');
                        const adminLink = document.createElement('a');
                        adminLink.href = 'admin.html';
                        adminLink.textContent = '用户管理';
                        adminLink.style.color = '#e74c3c';
                        nav.insertBefore(adminLink, nav.lastElementChild);
                    }
                } else {
                    console.error('获取用户信息失败:', result.message);
                }
            } catch (error) {
                console.error('获取用户信息失败:', error);
            }
        }
        
        function logout() {
            if (confirm('确定要退出登录吗？')) {
                localStorage.removeItem('token');
                window.location.href = 'login.html';
            }
        }
    </script>
</body>
</html> 